package com.wanghlme.leetcodecn;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>剑指 Offer 50. 第一个只出现一次的字符</p>
 *
 * @author wanghlme
 * @version 1.0
 */
public class LC_JZ50 {
    public static void main(String[] args) {

    }

    static class Solution {
        public char firstUniqChar(String s) {
            int len = s.length();
            if (len == 0) return ' ';
            if (len == 1) return s.charAt(0);
            Map<Character, Integer> map = new HashMap<>();
            for (int i = 0; i < len; i++) {
                char c = s.charAt(i);
                map.put(c, map.getOrDefault(c, 0) + 1);
            }
            for (int i = 0; i < len; i++) {
                if (map.get(s.charAt(i)) == 1) {
                    return s.charAt(i);
                }
            }
            return ' ';
        }
    }
}
